import { request } from "@/http/axios"
import type * as Entity from "./type"
const baseURL = import.meta.env.VITE_TRAIN_API

/** 增 */
export function createEntityDataApi(params: Entity.EntityBaseInfo) {
  return request<ApiResponseData<string>>({
    url: "/casia/model/entity/add",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    method: "post",
    data: params
  })
}

/** 删 */
export function deleteEntityDataApi(ids: string[]) {
  return request({
    url: `/casia/model/entity/remove`,
    method: "delete",
    data: {
      ids
    }
  })
}

/** 改 */
export function updateEntityDataApi(params: any) {
  return request({
    url: "/casia/model/entity/edit",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data: params
  })
}

/** 上传实体附件 */
export function uploadEntityFilesApi(params: any) {
  return request({
    url: "/casia/model/entity/saveFiles",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data: params
  })
}

// 查询实体
export function searchEntityDataApi(params: Entity.PageTableRequestData) {
  return request<Entity.SearchEntityTableResponseData>({
    url: "/casia/model/entity/search",
    method: "post",
    params: {
      pageSize: params.pageSize,
      pageNum: params.current
    },
    data: params
  })
}

/** 根据id查询实体及装配模型 */
export function getEntityInfoApi(id: string) {
  return request<Entity.EntityViewInfoResponseData>({
    url: `/casia/model/entity/getEntityInfo/${id}`,
    method: "get"
  })
}

/** 根据id获取实体模型信息 */
export function getEntityModelApi(id: string) {
  return request<Entity.ModelViewInfoResData>({
    url: `/casia/model/entity/typing/getInfo/${id}`,
    method: "get"
  })
}

/** 编辑实体模型 */
export function updateEntityModelApi(data: Entity.ModelDetailInfo) {
  return request({
    url: `/casia/model/entity/typing/edit`,
    method: "post",
    data
  })
}

/** 添加实体模型 */
export function addEntityModelApi(data: Entity.ModelDetailInfo) {
  return request({
    url: `/casia/model/entity/typing/add`,
    method: "post",
    data
  })
}


/** 删除实体模型 */
export function deleteEntityModelApi(ids: string[]) {
  return request({
    url: `/casia/model/entity/typing/remove`,
    method: "delete",
    data: {
      ids
    }
  })
}

export function getComponentApi() {
  return request<Entity.ComponentResData>({
    url: `/toksim/model/component/list`,
    method: "post"
  })
}

export function getComponentFieldApi(data: { componentId: string; staticFlag: boolean }) {
  return request<Entity.ComponentFieldResData>({
    url: `/toksim/model/component/getFieldsCollection`,
    method: "post",
    data
  })
}

export function getTaskTagApi(params: any) {
  return request({
    url: "/toksim/model/tag/list",
    method: "post",
    data: params
  })
}

// 新增标签
export function addTagApi(data: any) {
  return request({
    url: `/toksim/model/tag/add`,
    method: "post",
    data
  })
}

// 查询标签
export function searchClassifyApi(params: Entity.PageTableRequestData) {
  return request({
    url: "/casia/model/entity/searchClassify",
    method: "post",
    data: params
  })
}
// 2.3　七类码
// 查询domain
export function getDomainApi(kind: any) {
  return request<Entity.SevenCodeResData>({
    url: `/casia/model/sevencode/getDomain/${kind}`,
    method: "get",
  })
}

// 根据类型获取
export function getByTypeApplicabilityApi(data: { type: string, applicability?: string }) {
  return request<Entity.SevenCodeResData>({
    url: `/casia/model/sevencode/getByTypeApplicability`,
    method: "post",
    data
  })
}

// 操作附件fromData格式
export function saveFileApi(data: any) {
  return request({
    url: `/casia/model/entity/saveFiles`,
    headers: {
      "Content-Type": "multipart/form-data"
    },
    method: "post",
    data
  })
}

// 下载附件
export function downloadFileApi(params: any) {
  return request({
    url: "/toksim/model/fileAttachment/downloadFile",
    method: "get",
    responseType: "blob",
    params
  })
}